import numpy as np
import pandas as pd
import random


def generate_data(num_samples, feature_ranges, label_value):
    # 生成随机的特征数字
    num_features = len(feature_ranges)
    data = np.zeros((num_samples, num_features + 1))
    for i, (min_val, max_val) in enumerate(feature_ranges):
        data[:, i] = np.random.uniform(min_val, max_val, size=num_samples)
    data[:, -1] = label_value - 1

    # 标准化特征数字
    feature = data[:, :-1]
    feature_min = np.min(feature, axis=0)
    feature_max = np.max(feature, axis=0)
    normalized_feature = (feature - feature_min) / (feature_max - feature_min)
    normalized_data = np.concatenate((normalized_feature, data[:, -1].reshape(-1, 1)), axis=1)

    return normalized_data




def main():
    # 定义每个特征数字的范围
    feature_ranges = [(2., 3.), (0, 0.1), (20, 28)]

    # 生成100条标签数字为1的数据记录
    data1 = generate_data(300, feature_ranges, 1)

    # 生成100条标签数字为2的数据记录
    feature_ranges = [(1.7, 2.), (0.1, 0.15), (29, 34)]

    # 生成100条标签数字为1的数据记录
    data2 = generate_data(300, feature_ranges, 2)

    feature_ranges = [(0, 1.7), (0.15, 1), (35, 50)]

    # 生成100条标签数字为1的数据记录
    data3 = generate_data(300, feature_ranges, 3)

    # 将两份数据合并
    data = np.concatenate((data1, data2, data3), axis=0)

    # 转换成DataFrame并保存成CSV文件
    df = pd.DataFrame(data, columns=['Vol', 'R', 'Temp',  'label'])
    df.to_csv('data.csv', index=False)


if __name__ == '__main__':
    main()
